package com.xiaomi.controller;

import com.alibaba.fastjson.JSON;
import com.xiaomi.entity.ShopSku;
import com.xiaomi.model.Result;
import com.xiaomi.service.ShopSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping(value = "/xiaomi", produces = "application/json; charset=utf-8")
public class ShopSkuController {
   @Autowired
private ShopSkuService shopSkuService;

    @GetMapping("/sku/update.do")
    @ResponseBody
    public String update(ShopSku shopSku) throws Exception {
      shopSkuService.update(shopSku);
        //封装
        Result result = new Result();
        result.setCode(0);
        result.setMsg("修改成功");

        String json = JSON.toJSONString(result);
        return json;
    }

    @GetMapping("/sku/del.do")
    @ResponseBody
    public String delete(@RequestParam(required = false) Integer id) throws Exception {
        //传输数据
        shopSkuService.delete(id);

        //封装
        Result result = new Result();
        result.setCode(0);

        String json = JSON.toJSONString(result);
        return json;
    }

}
